﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sys_class_tree.aspx.cs" Inherits="Ccit.SysPlat.Organ.sys_class_tree" %>
<%@ Register assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="Microsoft.Web.UI.WebControls" tagprefix="iewc" %>
<html>
<head runat="server">
    <title></title>
    <style>
		.skin { BORDER-RIGHT: buttonhighlight 2px outset; BORDER-TOP: buttonhighlight 2px outset; FONT-SIZE: 9pt; VISIBILITY: hidden; BORDER-LEFT: buttonhighlight 2px outset; WIDTH: 100px; CURSOR: default; BORDER-BOTTOM: buttonhighlight 2px outset; FONT-FAMILY: Arial, Helvetica, sans-serif; POSITION: absolute; BACKGROUND-COLOR: menu; TEXT-ALIGN: left }
		.menuitems { PADDING-RIGHT: 4px; PADDING-LEFT: 4px; PADDING-TOP: 4px; PADDING-BOTTOM: 4px;}
	</style>
    <script type="text/javascript" src="../script/jquery.js"></script>
</head>
<body>
    <form id="form1" runat="server">   
     <input type="hidden" id="_hidOrganId" runat="server" /> 
    <input type="hidden" id="_hidAddNewSign" runat="server" /> <!-- 新增记录标志 -->
    <input type="hidden" id="_hidDelClsId" runat="server" />  
    <input type="hidden" id="_hidCurClsExpr" runat="server" />  
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
    </asp:ScriptManager>
    <div id="root" class="skin" style="LEFT:0px; VISIBILITY:hidden; WIDTH:90px; TOP:0px; HEIGHT:30px">
        <div onclick="clickItem()" onMouseover="highlighItem()" onMouseout="lowlightItem()"  class="menuitems" func="DelCls">            
                <img src="../images/toolbar/delete.gif" border="0" />&nbsp; 删除级别           
        </div>       
    </div>        
    <iewc:TreeView ID="trvCls" runat="server">
    </iewc:TreeView>
    <input type="button" id="btnTrigger" onclick="doTrigger()" style="display:none" value="触发事件" />
    <input type="button" id="btnDelTrigger" onclick="doDelTrigger()" style="display:none" value="删除触发事件" />
    </form>
     <script type="text/javascript">
    <!--
         var menuskin = "skin";
         var node = null;
         var menuname = "root";

         function hideMenu() {
             var obj = document.getElementById(menuname);
             if (null != obj && typeof (obj) != "undefined")
                 document.getElementById(menuname).style.visibility = "hidden";
         }

         function highlighItem() {
             if (event.srcElement.className == "menuitems") {
                 event.srcElement.style.backgroundColor = "highlight";
                 event.srcElement.style.color = "white";
             }
         }
         function lowlightItem() {
             if (event.srcElement.className == "menuitems") {
                 event.srcElement.style.backgroundColor = "";
                 event.srcElement.style.color = "black";
                 window.status = "";
             }
         }
         function clickItem() {
             if (node != null) {
                 var vClsId = node.getAttribute("ID");
                 var nodeType = node.getAttribute("type").toUpperCase();
                 var vOrganId = $get("_hidOrganId").value;

                 if (event.srcElement.className == "menuitems" && event.srcElement.disabled != true) {
                     var sFuncName = event.srcElement.getAttribute("func");
                     switch (sFuncName) {
                         case "DelCls": //删除级别					    
                             hideMenu();
                             if (!confirm("删除当前级别,是否继续?")) return;
                             var nodeIndex = node.getNodeIndex();
                             PageMethods.DeleteCls(vClsId, nodeIndex, ClientCallBack);

                             break;
                         default:
                             break;
                     }
                 }
             }
         }

         function trvCls.oncollapse() {
             hideMenu();
         }

         function trvCls.oncontextmenu() {
             hideMenu();
             var nodeIndex = event.treeNodeIndex;
             if (typeof (nodeIndex) == "undefined") {
                 node = null;
                 return false;
             }
             trvCls.selectedNodeIndex = nodeIndex;
             node = trvCls.getTreeNode(nodeIndex);
             var vCls = node.getAttribute("ID");
             if (vCls == "0") return;  //根节点不显示右键菜单

             var obj = document.getElementById("root");
             if (null == obj || typeof (obj) == "undefined") {
                 node = null;
                 return false;
             }

             var rightedge = document.body.clientWidth - event.clientX; 	//右边距
             var bottomedge = document.body.clientHeight - event.clientY; //底边距

             if (rightedge < obj.offsetWidth)
                 obj.style.left = document.body.scrollLeft + 5 + event.clientX - obj.offsetWidth;
             else
                 obj.style.left = document.body.scrollLeft + 5 + event.clientX;

             if (bottomedge < obj.offsetHeight)
                 obj.style.top = document.body.scrollTop + 5 + event.clientY - obj.offsetHeight;
             else
                 obj.style.top = document.body.scrollTop + 5 + event.clientY;

             obj.style.visibility = "visible";
             return false;
         }

         function ClientCallBack(vResult) {
             if (null == vResult || vResult == "undefined") {
                 alert("网络传输错误,没有正确的返回值,请检查网络是否畅通!");
                 return;
             }
             eval("var resultObj=" + vResult);
             var operType = resultObj.OPERTYPE;
             switch (operType) {
                 case "CLSDELETE":  //删除级别
                     var nodeIndex = resultObj.NODEINDEX;
                     alert(resultObj.RSTMSG);
                     if (parseInt(resultObj.RSTSIGN) > 0) {
                         var node = $get("trvCls").getTreeNode(nodeIndex);
                         node.remove();
                         parent.frames[1].initAddNew();
                     }
                     break;
             }

             resultObj = null;
         }

         function createSubTreeNodes(nodeIndex, subClsArray) {
             var node = $get("trvCls").getTreeNode(nodeIndex);
             var vOrganId = $get("_hidOrganId").value;
             var vClsId;
             var vClsName;
             var vNavigateUrl;
             var itemCount = subClsArray.length;
             var subCls;
             var vPageParam;
             var encodeParam;

             var newNodeIndex = "";
             for (var i = 0; i < itemCount; i++) {
                 subCls = subClsArray[i];
                 vClsId = subCls.clsId;
                 vClsName = subCls.clsName;
                 vPageParam = "organId=" + vOrganId + "&clsId=" + vClsId;
                 encodeParm = base64encode(vPageParam);
                 vNavigateUrl = "./sys_class_edit.aspx?" + encodeParm;
                 oSubNode = $get("trvCls").createTreeNode();
                 oSubNode.setAttribute("ID", vClsId);
                 oSubNode.setAttribute("Text", vClsName);
                 oSubNode.setAttribute("Type", "root");
                 oSubNode.setAttribute("Target", "ifrmEdit");
                 oSubNode.setAttribute("ImageUrl", "../images/organ/cls.gif");
                 oSubNode.setAttribute("NavigateUrl", vNavigateUrl);

                 node.add(oSubNode);
             }

             newNodeIndex = oSubNode.getNodeIndex();
             return newNodeIndex;
         }

         function findTreeNode(findClsId) {
             var ctrlTree = document.getElementById("trvCls");

             var ctrlRoot = ctrlTree.getTreeNode("0");
             var ctrlChildNodes = ctrlRoot.getChildren();

             var ctrlFindNode = recursionFind(ctrlChildNodes, findClsId);
             return ctrlFindNode;

         }

         function recursionFind(ctrlChildNodes, findClsId) {
             var iLen = ctrlChildNodes.length;
             var ctrlTreeNode;             
             var vPosId;
             var ctrlSubChildNodes;
             var bFind = false;

             for (var i = 0; i < iLen; i++) {
                 ctrlTreeNode = ctrlChildNodes[i];
                 vClsId = ctrlTreeNode.getAttribute("ID");
                 if (vClsId == findClsId) {
                     bFind = true;
                     break;
                 }
                 else {
                     ctrlSubChildNodes = ctrlTreeNode.getChildren();
                     ctrlTreeNode = recursionFind(ctrlSubChildNodes, findClsId);
                     if (null != ctrlTreeNode) {
                         bFind = true;
                         break;
                     }

                 }
             }

             if (bFind)
                 return ctrlTreeNode;
             else
                 return null;
         }

         function doTrigger() {
             var isAddNew = $get("_hidAddNewSign").value;
             eval("var curNodeObj=" + $get("_hidCurClsExpr").value);
             var curNodeIndex = 0;
             if (isAddNew == "1") {//编辑               
                 var curNodeId = curNodeObj.clsId;
                 var curNode = findTreeNode(curNodeId);
                 curNode.setAttribute("Text", curNodeObj.clsName);
                 curNodeIndex = curNode.getNodeIndex();
             }
             else {
                 var subClsArray = [];
                 subClsArray.push(curNodeObj);
                 curNodeIndex = createSubTreeNodes("0", subClsArray);
                 subClsArray = null;
             }


             curNodeObj = null;
             expandRoot();  //展开根节点
             $get("trvCls").selectedNodeIndex = curNodeIndex;
         }


         function doDelTrigger() {
             var delClsId = $get("_hidDelClsId").value;
             ctrlNode = findTreeNode(delClsId);
             nodeIndex = ctrlNode.getNodeIndex();
             var node = $get("trvCls").getTreeNode(nodeIndex);
             node.remove();
         }

         function expandRoot() {
             var ctrlRoot = $get("trvCls").getTreeNode("0");
             ctrlRoot.setAttribute("EXPANDED", true);
         }
      
    //-->
    </script>    
</body>
</html>
